package com.zhongke.cotrun.mapper;

import com.zhongke.cotrun.model.pojo.ExpertInfo;
import com.zhongke.cotrun.model.pojo.UserInfo;
import com.zhongke.cotrun.model.pojo.UserInfoExpert;
import org.apache.ibatis.annotations.Insert;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;

public interface ExpertInfoMapper {


    /**
     * 新建专家信息表
     * 默认审核通过正式发布改为待审核
     *
     * @param expertInfo
     * @return head_portrait
     */
    @Insert("INSERT INTO `expert_info` (`research_area`, `research`, `job_title`, `get_time`, `title_certificate`, `ncp`, `get_ncp`, `ncp_address`," +
            "`head_portrait`, `individual`, `show_public`, `full_name`, `create_time`,`link_user_id`,`expert_link`,`top_title`) VALUES (#{researchArea}, #{research}, #{jobTitle}," +
            " #{getTime}, #{titleCertificate}, #{ncp}, #{getNcp}, #{ncpAddress}, #{headPortrait}, #{individual}, #{showPublic}, #{fullName}, NOW(), #{linkUserId}, #{expertLink},#{topTitle})")
    public boolean insertExperInfo(ExpertInfo expertInfo);

    /**
     * 修改审核状态
     *
     * @param expertInfo
     * @return
     */
    @Update("UPDATE expert_info SET audit_status=#{auditStatus} ,remark=#{remark} WHERE expert_id=#{expertId}")
    public boolean updateAuditStatus(ExpertInfo expertInfo);

    /**
     * 修改信息
     *
     * @param expertInfo
     * @return
     */
    public Boolean updateExpertInfo(ExpertInfo expertInfo);


    //查看专家列表

    public List<ExpertInfo> selectExpertByCondition(UserInfo userInfo);

    //查看具体或自己的或者所有的不传值为所有的
    public ExpertInfo selectExpertById(ExpertInfo expertInfo);


    /**
     * 查看自己的专家信息
     */

    @Select("SELECT * FROM expert_info WHERE link_user_id =#{userId}")
    public ExpertInfo selectMyExpertByuUserId(Integer userId);

    /**
     * 根据id查看专家信息
     * @param
     * @return
     */
    @Select("SELECT * FROM expert_info WHERE expert_id =#{id}")
    public ExpertInfo selectMyExpertByuId(Integer id);

    /**
     * 审核通过
     * @param id
     * @param userName
     * @return
     */
    @Update("update expert_info set audit_status = 1,audit_user = #{userName},audit_time = now() where expert_id = #{id}")
    boolean approvalPass(Long id, String userName);

    /**
     * 审核驳回
     * @param id
     * @param userName
     * @param auditOpinion
     * @return
     */
    @Update("update expert_info set audit_status = 2,audit_user = #{userName},audit_time = now(),audit_opinion = #{auditOpinion} where expert_id = #{id}")
    boolean approvalRejected(Long id, String userName, String auditOpinion);

    @Select("select ui.user_id,ui.real_name,ui.work_unit,ui.sex,ui.birthdate,ui.email,ui.province,ui.city,ui.work_unit,ei.* " +
            "from user_info ui left join expert_info ei on ui.user_id = ei.link_user_id where ui.user_id = #{id}")
    UserInfoExpert selectExpertInfoByUserId(@Param("id") Integer id);
}
